package com.ruoyi.web.publish.issue.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.publish.issue.mapper.IssueHistoryMapper;
import com.ruoyi.web.publish.issue.domain.IssueHistory;
import com.ruoyi.web.publish.issue.service.IIssueHistoryService;
import org.springframework.util.CollectionUtils;

/**
 * 发行历史Service业务层处理
 *
 * @author ruoyi
 * @date 2021-08-24
 */
@Service
public class IssueHistoryServiceImpl implements IIssueHistoryService {
    @Autowired
    private IssueHistoryMapper issueHistoryMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询发行历史
     *
     * @param id 发行历史主键
     * @return 发行历史
     */
    @Override
    public IssueHistory selectIssueHistoryById(Long id) {
        return issueHistoryMapper.selectIssueHistoryById(id);
    }

    /**
     * 查询发行历史列表
     *
     * @param issueHistory 发行历史
     * @return 发行历史
     */
    @Override
    public List<IssueHistory> selectIssueHistoryList(IssueHistory issueHistory)
    {
        return issueHistoryMapper.selectIssueHistoryList(issueHistory);
    }

    /**
     * 查询发行历史列表
     *
     * @param issueHistory 发行历史
     * @return 发行历史
     */
    @Override
    public List<IssueHistory> selectMyIssueHistoryList(IssueHistory issueHistory)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        issueHistory.setCreateById(user.getUserId());
        issueHistory.setCreateBy(user.getUserName());
        return issueHistoryMapper.selectMyIssueHistoryList(issueHistory);
    }

    /**
     * 新增发行历史
     *
     * @param issueHistory 发行历史
     * @return 结果
     */
    @Override
    public int insertIssueHistory(IssueHistory issueHistory) {
        issueHistory.setCreateTime(DateUtils.getNowDate());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        issueHistory.setCreateById(user.getUserId());
        issueHistory.setCreateBy(user.getUserName());

        return issueHistoryMapper.insertIssueHistory(issueHistory);
    }

    /**
     * 修改发行历史
     *
     * @param issueHistory 发行历史
     * @return 结果
     */
    @Override
    public int updateIssueHistory(IssueHistory issueHistory) {
        issueHistory.setUpdateTime(DateUtils.getNowDate());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        issueHistory.setUpdateById(user.getUserId());
        issueHistory.setUpdateBy(user.getUserName());
        return issueHistoryMapper.updateIssueHistory(issueHistory);
    }

    /**
     * 批量删除发行历史
     *
     * @param ids 需要删除的发行历史主键
     * @return 结果
     */
    @Override
    public int deleteIssueHistoryByIds(Long[] ids)
    {
        return issueHistoryMapper.deleteIssueHistoryByIds(ids);
    }

    /**
     * 删除发行历史信息
     *
     * @param id 发行历史主键
     * @return 结果
     */
    @Override
    public int deleteIssueHistoryById(Long id)
    {
        return issueHistoryMapper.deleteIssueHistoryById(id);
    }
}
